import Vue from 'vue'
import Router from 'vue-router'

// const originalPush = Router.prototype.push
// Router.prototype.push = function push(location, onResolve, onReject) {
//   if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
//   return originalPush.call(this, location).catch(err => err)
// }
Vue.use(Router);

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const constRouterMap = [

  {
    path: '/',
    redirect: '/index',
  }, {
    path: '/index',
    name: 'index',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/index/index.vue'], resolve),
    meta: {
      keepAlive: true
    }
  },
  {
    path: '/login',
    name: 'login',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/login.vue'], resolve),
    meta: {
      keepAlive: true
    }
  },
  {
    path: '/register',
    name: 'register',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/register.vue'], resolve),
    meta: {
      keepAlive: true
    }
  },
  {
    path: '/index_detail',
    name: 'index_detail',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/index/index_detail.vue'], resolve),

  },
  {
    path: '/activity',
    name: 'activity',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/index/activity.vue'], resolve),

  },
  {
    path: '/activity_list',
    name: 'activity_list',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/my/activity_list.vue'], resolve),

  },
  {
    path: '/me',
    name: 'me',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/my/me.vue'], resolve),

  },
  {
    path: '/jpList',
    name: 'jpList',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/jp/jpList.vue'], resolve),

  },
  {
    path: '/jpListDetail',
    name: 'jpListDetail',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/jp/jpListDetail.vue'], resolve),

  },
  {
    path: '/new_pass',
    name: 'new_pass',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/my/new_pass.vue'], resolve),

  },
  {
    path: '/information',
    name: 'information',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/my/information.vue'], resolve),

  },
  {
    path: '/See',
    name: 'See',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/my/See.vue'], resolve),

  },
  {
    path: '/about',
    name: 'about',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/my/about.vue'], resolve),

  },
  {
    path: '/wait',
    name: 'wait',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/my/wait.vue'], resolve),

  },
  {
    path: '/wait_detail',
    name: 'wait_detail',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/my/wait_detail.vue'], resolve),

  },
  {
    path: '/Statistics',
    name: 'Statistics',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/my/Statistics.vue'], resolve),

  },
  {
    path: '/Statistics_detail',
    name: 'Statistics_detail',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/my/Statistics_detail.vue'], resolve),

  },
  {
    path: '/service',
    name: 'service',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/my/service.vue'], resolve),

  },
  {
    path: '/account',
    name: 'account',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/my/account.vue'], resolve),

  },
  {
    path: '/pay_see',
    name: 'pay_see',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/my/pay_see.vue'], resolve),

  },
  {
    path: '/detailed',
    name: 'detailed',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/my/detailed.vue'], resolve),

  },
  {
    path: '/recharge',
    name: 'recharge',
    //异步加载  一个组件生成一个js
    component: resolve => require(['@/views/my/recharge.vue'], resolve),

  },
];


const router = new Router({
  routes: constRouterMap,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return {
        x: 0,
        y: 0
      }
    }
  }
});

export default router
